package com.cat.binaryTree;

import java.util.ArrayList;
import java.util.List;

/**
 * @author 曲大人的喵
 * @description https://leetcode.cn/problems/binary-tree-right-side-view/
 * @create 2025/9/9 22:15
 * @since JDK17
 */

public class Solution06 {
    List<Integer> ans = new ArrayList<>();

    void dfs(TreeNode root, int cur) {
        if (root == null) {
            return;
        }
        if (ans.size() == cur) {
            ans.add(root.val);
        }
        dfs(root.right, cur + 1);
        dfs(root.left, cur + 1);
    }

    public List<Integer> rightSideView(TreeNode root) {
        dfs(root, 0);
        return ans;
    }
}
